# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  include Cobra::Util
  model :user
  
  before_filter :setup_user_context
  #before_filter :login_required
  # currently we use application.rhtml as our default layout.
  #layout "default", :except => :home           # set layout name 'default'.

  def setup_user_context
          @action_hash = controller_hash()
          @action_config ||= {}
          #TOTO:  make up Locale according to user profile setting.
          #  Currently hard coding it here as "en_US"
          #  We may put the following into session container.
          @locale = get_default_locale()
          @context = Cobra::Util::Context.new
          @context.set_locale(@locale);
          
#          if @session[:_USER_ID_]
#             unless @context_user
#                begin
#                   @context_user = User.find(@session[:_USER_ID_])      
#                rescue ActiveRecord::RecordNotFound
#                   reset_session  # remove session.
#                end   
#                       
#             end
#             @context.set_user(@context_user)  
#          end
  end


  def get_default_locale
    return Cobra::Util::Locale.new("zh_CN")
  end
  
  
  #This method is possibly overrided by child controller class.
  protected 
  #keep them as empty, those are abstract methods.
  def action_auth_hash()  
  end
 
  def controller_hash()
  end
  #did some work before call action
  def pre_action()
  end
  

end